<?php
include_once 'connection/connection_database.php';
include_once 'app/model/board/process.php';
include_once 'app/model/page/process.php';
include_once 'app/model/comment/process.php';
include_once 'app/model/contact/process.php';
include_once 'app/function/xulychuoi.php';

$contact = new Contacts();
$fillOne = $contact->FillOne();

$board = new Boards();
$pages = new Pages();
$comment = new Comment();
$menu = $_GET["menu"];

$pageByUrl = mysql_fetch_array($pages->FillByPageLink($menu));
$boardByPage = mysql_fetch_array($board->FillByPageUrl($menu));
$pages->UpdatePageCounter($pageByUrl["page_id"], $pageByUrl["page_counter"]);
//comment
$commentByPage = $comment->FillByPage($pageByUrl["page_id"]);
$i = 0;
$numPage = 10;
if (!$_GET["page"]) {
    $page = 1;
} else if ((int) $_GET["page"]) {
    $page = $_GET["page"];
}
$sodu = mysql_num_rows($commentByPage);

$sotrang = ceil($sodu / $numPage);
$pageCurrent = (($page * $numPage) - $numPage);
$sql = "SELECT * FROM comment WHERE page_id='{$pageByUrl["page_id"]}' and comment_status=1 ORDER BY page_id ASC LIMIT {$pageCurrent},{$numPage}";

$resultPagingComment = mysql_query($sql);
$urlHome = explode("/", $url["home"]);
?>
<div id="about_company">
	<?php
		//Tạo hiệu ứng sau mỗi lần refresh trình duyệt bức ảnh quảng cáo sẽ thay đổi
		//Mảng chứa tên các bức ảnh
		$images = array("banner_top" => "banner_top", "banner_top2" => "banner_top2");
		//Biến lưu tên ảnh được lấy ngẫu nhiên từ mảng
		$randImages = array_rand($images);
	?>            						
    <img width="710" height="150" src="<?php echo $url["home"] ?>/images/upload/<?php echo $randImages ?>.gif">
    <div class="duong_dan">
        <a href="index.html"><img src="<?php echo $url["home"] ?>/images/icon-home.png">  Trang chủ <img alt="" src="<?php echo $url["home"] ?>/images/rarrow.png"></a>
        <a href="<?php echo $boardByPage["board_url"] . ".html" ?>"><?php echo $boardByPage["board_name"] ?></a>
        <img alt="" src="<?php echo $url["home"] ?>/images/rarrow.png"><a href="<?php echo $pageByUrl["page_link"] . ".html" ?>"><?php echo $pageByUrl["page_title"] ?></a>
        <span class="counter_view">Có <?php echo $pageByUrl["page_counter"] ?> lượt xem</span>
        <hr width="100%" size="1" color="#CCCCCC">
    </div><!-- End .duong_dan-->
    <div id="noi_dung_bai_viet">
        <div class="noi_dung_chinh">
            <h2><img src="<?php echo $url["home"] ?>/images/icon-9.png">  <a href="<?php echo $pageByUrl["page_link"] . ".html" ?>"><?php echo $pageByUrl["page_title"] ?></a></h2>
            <hr width="100%" size="1" color="#CCCCCC">
            <div>
                <div>
                    <?php echo $pageByUrl["page_content"] ?>
                    <p class="textRight">Công ty TNHH tư vấn BRAVO.</p>
                    <p class="tags_article">
                        <img src="<?php echo $url["home"] ?>/images/tags-1.png">
                        <?php
                        $tags = explode(",", $pageByUrl["page_tag"]);
                        foreach ($tags as $_tags) {
							$_tags = trim(khongdau($_tags));
							$link_tags = strtolower(preg_replace('/[^a-z0-9]+/i','-',$_tags));
                            ?>
                            <a href="<?php echo $url["home"] ?>/tag/<?php echo $link_tags; ?>"><?php echo $_tags; ?></a> |
                        <?php } ?>
                    </p>
                    <div class="comments like share">
                        <div id="fb-root"></div>
                        <script>(function(d, s, id) {
                            var js, fjs = d.getElementsByTagName(s)[0];
                            if (d.getElementById(id)) return;
                            js = d.createElement(s); js.id = id;
                            js.src = "//connect.facebook.net/vi_VN/all.js#xfbml=1";
                            fjs.parentNode.insertBefore(js, fjs);
                        }(document, 'script', 'facebook-jssdk'));</script>
                        <div class="fb-like" data-href="<?php echo $urlHome[1]."/".$pageByUrl["page_link"].".html" ?>" data-send="true" data-layout="button_count" data-width="450" data-show-faces="true"></div>
                        <!-- AddThis Button BEGIN -->
                        <div class="addthis_toolbox addthis_default_style ">
                        <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                        <a class="addthis_button_tweet"></a>
                        <a class="addthis_button_pinterest_pinit"></a>
                        <a class="addthis_counter addthis_pill_style"></a>
                        </div>
                        <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-50fdf6e91b97493b"></script>
                        <!-- AddThis Button END -->
                    </div><!--End .comments-->
                    <div class="adress_company">
                        <hr width="100%" size="1" color="#CCCCCC">
                        <h3>Mọi chi tiết về <?php echo $pageByUrl["page_title"] ?> xin vui lòng liên hệ :</h3>
                        <p>
                        	<?php if ($fillOne) { $rows = mysql_fetch_array($fillOne) ; ?>
                            <span class="text_bold">Công ty TNHH tư vấn Bravo</span><br>
                            <b><i>Địa chỉ : </i></b> <?php echo $rows["contact_address"]; ?> <br>
                            <b><i>Hotline : </i></b> <?php echo $rows["contact_telephone"] ; ?>   -  <?php echo $rows["contact_phone"]; ?> <br>
                            <b><i>Website : </i></b> www.bravolaw.vn / www.bravolaw.com.vn / www.luatsuonline.vn
                            <?php } ?>
                        </p>
                    </div><!-- ENd .adress_company-->
                </div>
            </div>
            <div id="comment">
                <fieldset>
                    <legend>Gửi bình luận của bạn </legend>
                    <form method="post" action="process-comment">
                        <ol>
                            <li>
                                <label for="signed">
                                    Họ tên :
                                </label>
                            </li>
                            <li>
                                <input type="hidden" value="<?php echo $pageByUrl["page_id"] ?>" name="page_id"/>
                                <input type="text" size="50" value="Nhập vào họ tên..." onblur="if (this.value=='') this.value='Nhập vào họ tên...';" onfocus="if (this.value=='Nhập vào họ tên...') this.value='';" name="comment_name" id="comment_name">
                                <span id="errUserName" style="display: none"><p>Họ tên không được để trống !</p></span>
                            </li>
                            <li>
                                <label for="content_Comment">
                                    Nội dung comment :
                                </label>
                            </li>
                            <li>
                                <textarea rows="6" cols="60" name="comment_description" id="comment_description"></textarea>
                                <script type="text/javascript">CKEDITOR.replace('texteditorContentComment'); </script>
                                <span id="errDescription" style="display: none"><p>Nội dung không được để trống !</p></span>
                            </li>
                            <li>
                                <input type="submit" value="Gửi Comment" name="send_comment" id="send_comment">
                                <input type="reset" value="Soạn lại" name="btn_Refresh_Comment">
                            </li>
                        </ol>
                    </form>
                </fieldset>

            </div>
            <div class="danh_sach_comment">
                <h2><img src="<?php echo $url["home"] ?>/images/Comment.png">Danh sách comment cho bài viết này</h2>
                <p>Có : <?php echo mysql_num_rows($commentByPage); ?> comment bài viết này</p>
                <?php if (mysql_num_rows($commentByPage) != 0 ) : ?>
                <div>
                    <?php while ($commentPage = mysql_fetch_array($resultPagingComment)) : ?>
                        <div>
                            <img src="<?php echo $url["home"] ?>/images/comment_user.png"><i>Người viết :</i> <?php echo $commentPage["comment_name"] ?>
                            <p>
                                <?php echo $commentPage["comment_description"] ?>
                            </p>
                        </div>
                        <hr width="100%" size="1" color="#CCCCCC">
                    <?php endwhile; ?>
                </div>
                <div id="paginate">
                	<ul class="nav">
						<?php
                        for ($i = 1; $i <= $sotrang; $i++) {
                            if ($page == $i) {
                                echo "<li><a href='javascript: void(0)'> [ {$i} ] </a></li>";
                            } else {
                                echo "<li><a href='{$url["home"]}/{$pageByUrl["page_link"]}/p/{$i}'> [ {$i} ] </a></li>";
                            }
                        }
                        ?>
                    </ul>
                </div>
                <?php endif; ?>
            </div><!-- End #danh_sach_comment-->
            <div class="bai_viet_lien_quan">
                <h2>Bài viết liên quan</h2>
                <ul>
                    <?php 
                    $page_tag = explode(",", $pageByUrl["page_tag"]);
                    $count = 0;
                    $array = array();
                    $flag = false;
                    foreach($page_tag as $_page_tag){
                        $count++;
                        $resultFindAll = $pages->FindAll($_page_tag, $pageByUrl["page_id"]);
                        
                        
                        if($resultFindAll && $count < 10){
                            while($rowFindAll = mysql_fetch_array($resultFindAll)) {
                                foreach($array as $_array){
                                    if($_array == $rowFindAll["page_title"]){
                                        $flag = false;
                                    }else{
                                        $flag = true;
                                    }
                                }
                                $array[] = $rowFindAll["page_title"];
                                if($flag){
                    ?>
                        <li><h3><a href=""><img src="images/icon-article.png"> <?php echo $rowFindAll["page_title"] ?></a></h3></li>
                    <?php 
                                }
                            }
                        }
                    }
                    ?>
                </ul> 
            </div><!--End .bai_viet_lien_quan-->
            <div class="bai_viet_cung_chu_de">
                <h2>Bài viết cùng chủ đề</h2>
                <ul>
                    <?php
                        $resultPageByBoard = $pages->FillOneByBoard($pageByUrl["board_id"], $pageByUrl["page_id"]);
                        while($rowsPageByBoard = mysql_fetch_array($resultPageByBoard)) :
                    ?>
                        <li><h3><a href=""><img src="images/icon-article.png"> <?php echo $rowsPageByBoard["page_title"] ?></a></h3></li>
                    <?php endwhile; ?>
                </ul> 
            </div><!--End .bai_viet_cung_chu_de-->
            <div class="clear"></div><!-- End .clear-->
        </div><!--End #noi_dung_chinh-->
    </div><!--End #noi_dung_bai_viet-->
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $('#send_comment').click(isCheckComment);
    });
</script>